home *** CD-ROM | disk | FTP | other *** search
- /*
- gifHeader.c
-
- gifheader.c, gifbmap.c, and gif.h are based on "giftoppm"
- of David Koblas.
- They are modified by T. Ogihara. (1995)
- */
-
- /* +-------------------------------------------------------------------+ */
- /* | Copyright 1990, David Koblas. | */
- /* | Permission to use, copy, modify, and distribute this software | */
- /* | and its documentation for any purpose and without fee is hereby | */
- /* | granted, provided that the above copyright notice appear in all | */
- /* | copies and that both that copyright notice and this permission | */
- /* | notice appear in supporting documentation. This software is | */
- /* | provided "as is" without express or implied warranty. | */
- /* +-------------------------------------------------------------------+ */
-
- #include <stdio.h>
- #include "gif.h"
-
- gifHeader *loadGifHeader(FILE *fd, int *errcode)
- {
- unsigned char buf[16];
- gifHeader *gh;
- int cc;
-
- if (! ReadOK(fd,buf,6)) {
- *errcode = Err_FORMAT;
- return NULL;
- }
- buf[6] = 0;
- if (strcmp(buf,"GIF87a") != 0 && strcmp(buf,"GIF89a") != 0) {
- *errcode = Err_FORMAT;
- return NULL;
- }
- if ((gh = (gifHeader *)malloc(sizeof(gifHeader))) == NULL) {
- *errcode = Err_MEMORY;
- return NULL;
- }
- gh->width = get_short(fd);
- gh->height = get_short(fd);
- gh->colors = 2 << ((cc = getc(fd)) & 0x07);
- gh->Resolution = ((cc & 0x70) >> 3) + 1;
- gh->colormap = BitSet(cc, LOCALCOLORMAP);
- gh->interlace = BitSet(cc, INTERLACE);
- gh->Background = getc(fd);
- gh->AspectRatio = getc(fd);
- strcpy(gh->ver, buf+3);
- gh->palette = NULL;
- gh->memo = NULL;
- return gh;
- }
-
- void freeGifHeader(gifHeader *gh)
- {
- if (gh) {
- if (gh->palette) free((void *)gh->palette);
- if (gh->memo) free((void *)gh->memo);
- free((void *)gh);
- }
- }
-
- commonInfo *gifInfo(gifHeader *gh, int bits, BOOL mono)
- /* Convert gif-header into commonInfo */
- {
- commonInfo *cinf;
- int i;
-
- if (gh == NULL) return NULL;
- cinf = (commonInfo *)malloc(sizeof(commonInfo));
- cinf->width = gh->width;
- cinf->height = gh->height;
- cinf->type = Type_gif;
- cinf->bits = bits;
- cinf->alpha = NO;
- cinf->isplanar = YES;
- cinf->numcolors = mono ? 1 : 3;
- cinf->cspace = mono ? NX_OneIsWhiteColorSpace : NX_RGBColorSpace;
- cinf->xbytes = byte_length(bits, gh->width);
- cinf->palette = gh->palette;
- gh->palette = NULL;
- cinf->palsteps = gh->colors;
- sprintf(cinf->memo, "%d x %d, GIF%s%s %d%s",
- gh->width, gh->height, gh->ver, gh->interlace?":interlace":"",
- gh->colors, mono?"steps":"colors");
- if (gh->memo) {
- strcat(cinf->memo, " ");
- i = strlen(cinf->memo);
- strncat(cinf->memo, gh->memo, MAX_COMMENT - i - 2);
- }
- return cinf;
- }
-